<?xml version="1.0" encoding="UTF-8" standalone="no"?>
{% import 'common/iso19139-charstring.j2' as cs %}
<gmd:MD_Metadata xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.isotc211.org/2005/gmd http://www.isotc211.org/2005/gmd/gmd.xsd http://www.isotc211.org/2005/gmx http://www.isotc211.org/2005/gmx/gmx.xsd">
  <gmd:fileIdentifier>
    <gco:CharacterString>{{ record['metadata']['identifier'] }}</gco:CharacterString>
  </gmd:fileIdentifier>
  <gmd:language>
    <gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/" codeSpace="ISO 639-2" codeListValue="{{ record['metadata']['language'] }}">{{ record['metadata']['language'] }}</gmd:LanguageCode>
  </gmd:language>
  <gmd:characterSet>
    <gmd:MD_CharacterSetCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_CharacterSetCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['metadata']['charset'] }}">{{ record['metadata']['charset'] }}</gmd:MD_CharacterSetCode>
  </gmd:characterSet>
  {% if record['metadata']['parentidentifier'] %}
  <gmd:parentIdentifier>
    <gco:CharacterString>{{ record['metadata']['parentidentifier'] }}</gco:CharacterString>
  </gmd:parentIdentifier>
  {% endif %}
  <gmd:hierarchyLevel>
    <gmd:MD_ScopeCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ScopeCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['metadata']['hierarchylevel'] }}">{{ record['metadata']['hierarchylevel'] }}</gmd:MD_ScopeCode>
  </gmd:hierarchyLevel>
  {% for key, value in record['contact'].items() %}
  {% if key not in ['distributor', 'pointOfContact'] %}
  <gmd:contact>
    {% set contact = value %}
    {% set role = key %}
    {% include "contact.j2" %}
  </gmd:contact>
  {% endif %}
  {% endfor %}
  <gmd:dateStamp>
    {% set datestamp = record['metadata']['datestamp']|normalize_datestring %}
    {% if datestamp|length > 11 %}
    <gco:DateTime>{{ datestamp }}</gco:DateTime>
    {% else %}
    <gco:Date>{{ datestamp }}</gco:Date>
    {% endif %}
  </gmd:dateStamp>
  <gmd:metadataStandardName>
    <gco:CharacterString>ISO 19115:2003 - Geographic information - Metadata</gco:CharacterString>
  </gmd:metadataStandardName>
  <gmd:metadataStandardVersion>
    <gco:CharacterString>ISO 19115:2003</gco:CharacterString>
  </gmd:metadataStandardVersion>
  <gmd:dataSetURI>
    <gco:CharacterString>{{ record['metadata']['dataseturi']|e }}</gco:CharacterString>
  </gmd:dataSetURI>
  {% if record['metadata']['language_alternate'] %}
  <gmd:locale>
    <gmd:PT_Locale id="locale-fr">
      <gmd:languageCode>
        <gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/" codeSpace="ISO 639-2" codeListValue="{{ record['metadata']['language_alternate'] }}">{{ record['metadata']['language_alternate'] }}</gmd:LanguageCode>
      </gmd:languageCode>
      <gmd:characterEncoding>
        <gmd:MD_CharacterSetCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_CharacterSetCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['metadata']['charset'] }}">{{ record['metadata']['charset'] }}</gmd:MD_CharacterSetCode>
      </gmd:characterEncoding>
    </gmd:PT_Locale>
  </gmd:locale>
  {% endif %}
  <gmd:spatialRepresentationInfo>
    {% if record['spatial']['datatype'] == 'vector' %}
    <gmd:MD_VectorSpatialRepresentation>
      <gmd:topologyLevel>
        <gmd:MD_TopologyLevelCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopologyLevelCode" codeSpace="ISOTC211/19115" codeListValue="geometryOnly">geometryOnly</gmd:MD_TopologyLevelCode>
      </gmd:topologyLevel>
      <gmd:geometricObjects>
        <gmd:MD_GeometricObjects>
          <gmd:geometricObjectType>
            <gmd:MD_GeometricObjectTypeCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_GeometricObjectTypeCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['spatial']['geomtype'] }}">{{ record['spatial']['geomtype'] }}</gmd:MD_GeometricObjectTypeCode>
          </gmd:geometricObjectType>
        </gmd:MD_GeometricObjects>
      </gmd:geometricObjects>
    </gmd:MD_VectorSpatialRepresentation>
    {% endif %}
  </gmd:spatialRepresentationInfo>
  <gmd:referenceSystemInfo>
    <gmd:MD_ReferenceSystem>
      <gmd:referenceSystemIdentifier>
        <gmd:RS_Identifier>
          <gmd:authority>
            <gmd:CI_Citation>
              <gmd:title>
                <gco:CharacterString>European Petroleum Survey Group (EPSG) Geodetic Parameter Registry</gco:CharacterString>
              </gmd:title>
              <gmd:date>
                <gmd:CI_Date>
                  <gmd:date>
                    <gco:Date>2008-11-12</gco:Date>
                  </gmd:date>
                  <gmd:dateType>
                    <gmd:CI_DateTypeCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode" codeSpace="ISOTC211/19115" codeListValue="publication">publication</gmd:CI_DateTypeCode>
                  </gmd:dateType>
                </gmd:CI_Date>
              </gmd:date>
              <gmd:citedResponsibleParty>
                <gmd:CI_ResponsibleParty>
                  <gmd:organisationName>
                    <gco:CharacterString>European Petroleum Survey Group</gco:CharacterString>
                  </gmd:organisationName>
                  <gmd:contactInfo>
                    <gmd:CI_Contact>
                      <gmd:onlineResource>
                        <gmd:CI_OnlineResource>
                          <gmd:linkage>
                            <gmd:URL>http://www.epsg-registry.org</gmd:URL>
                          </gmd:linkage>
                        </gmd:CI_OnlineResource>
                      </gmd:onlineResource>
                    </gmd:CI_Contact>
                  </gmd:contactInfo>
                  <gmd:role>
                    <gmd:CI_RoleCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode" codeSpace="ISOTC211/19115" codeListValue="originator">originator</gmd:CI_RoleCode>
                  </gmd:role>
                </gmd:CI_ResponsibleParty>
              </gmd:citedResponsibleParty>
            </gmd:CI_Citation>
          </gmd:authority>
          <gmd:code>
            <gco:CharacterString>urn:ogc:def:crs:EPSG:{{ record['identification']['extents']['spatial'][0]['crs'] }}</gco:CharacterString>
          </gmd:code>
          <gmd:version>
            <gco:CharacterString>6.18.3</gco:CharacterString>
          </gmd:version>
        </gmd:RS_Identifier>
      </gmd:referenceSystemIdentifier>
    </gmd:MD_ReferenceSystem>
  </gmd:referenceSystemInfo>
  <gmd:identificationInfo>
    <gmd:MD_DataIdentification>
      <gmd:citation>
        <gmd:CI_Citation>
          {{ cs.get_freetext('title', record['metadata']['language_alternate'], get_charstring(record['identification'].get('title'), record['metadata']['language'], record['metadata']['language_alternate'])) }}
          {% for date_type, date in record['identification']['dates'].items() %}
          {% set datestamp = date|normalize_datestring %}
          <gmd:date>
            <gmd:CI_Date>
              <gmd:date>
                {% if datestamp|length > 11 %}
                <gco:DateTime>{{ datestamp }}</gco:DateTime>
                {% else %}
                <gco:Date>{{ datestamp }}</gco:Date>
                {% endif %}
              </gmd:date>
              <gmd:dateType>
                <gmd:CI_DateTypeCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode" codeSpace="ISOTC211/19115" codeListValue="{{ date_type }}">{{ date_type }}</gmd:CI_DateTypeCode>
              </gmd:dateType>
            </gmd:CI_Date>
          </gmd:date>
          {% endfor %}
          {% if record['identification']['edition'] %}
          {{ cs.get_freetext('edition', record['metadata']['language_alternate'], get_charstring(record['identification'].get('edition'), record['metadata']['language'], record['metadata']['language_alternate'])) }}
          {% endif %}
        </gmd:CI_Citation>
      </gmd:citation>
      {{ cs.get_freetext('abstract', record['metadata']['language_alternate'], get_charstring(record['identification'].get('abstract'), record['metadata']['language'], record['metadata']['language_alternate'])) }}
      <gmd:status>
        <gmd:MD_ProgressCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ProgressCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['identification']['status'] }}">{{ record['identification']['status'] }}</gmd:MD_ProgressCode>
      </gmd:status>
      {% if 'pointOfContact' in record['contact'] %}
      {% set contact = record['contact']['pointOfContact'] %}
      {% set role = 'pointOfContact' %}
      <gmd:pointOfContact>
      {% include "contact.j2" %}
      </gmd:pointOfContact>
      {% endif %}
      <gmd:resourceMaintenance>
        <gmd:MD_MaintenanceInformation>
          <gmd:maintenanceAndUpdateFrequency>
            <gmd:MD_MaintenanceFrequencyCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_MaintenanceFrequencyCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['identification']['maintenancefrequency'] }}">{{ record['identification']['maintenancefrequency'] }}</gmd:MD_MaintenanceFrequencyCode>
          </gmd:maintenanceAndUpdateFrequency>
        </gmd:MD_MaintenanceInformation>
      </gmd:resourceMaintenance>
      {% if record['identification']['browsegraphic'] %}
      <gmd:graphicOverview>
        <gmd:MD_BrowseGraphic>
          <gmd:fileName>
            <gco:CharacterString>{{ record['identification']['browsegraphic']|e }}</gco:CharacterString>
            </gmd:fileName>
        </gmd:MD_BrowseGraphic>
      </gmd:graphicOverview>
      {% endif %}
      {% for key, value in record['identification']['keywords'].items() %}
      <gmd:descriptiveKeywords>
        <gmd:MD_Keywords>
        {% set keywords = get_charstring(value.get('keywords'), record['metadata']['language'], record['metadata']['language_alternate']) %}
        {% if keywords[0] is not none %}
        {% if keywords[1] is none %}
          {# No language_alternate is specified #}
          {% for kw1 in keywords[0] %}
          {{ cs.get_freetext('keyword', None, [kw1]) }}
          {% endfor %}
        {% else %}
          {% for kw1, kw2 in zip(keywords[0], keywords[1]) %}
          {{ cs.get_freetext('keyword', record['metadata']['language_alternate'], [kw1, kw2]) }}
          {% endfor %}
        {% endif %}
        {% endif %}
          <gmd:type>
            <gmd:MD_KeywordTypeCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_KeywordTypeCode" codeSpace="ISOTC211/19115" codeListValue="{{ value['keywords_type'] }}">{{ value['keywords_type'] }}</gmd:MD_KeywordTypeCode>
          </gmd:type>
          {% if key == 'wmo' %}
          <gmd:thesaurusName>
            <gmd:CI_Citation>
              <gmd:title>
                <gmx:Anchor xlink:href="http://wis.wmo.int/2012/codelists/WMOCodeLists.xml#WMO_CategoryCode"/>
              </gmd:title>
              <gmd:date>
                <gmd:CI_Date>
                  <gmd:date>
                    <gco:Date>2013-07-11</gco:Date>
                  </gmd:date>
                  <gmd:dateType>
                    <gmd:CI_DateTypeCode codeList="http://wis.wmo.int/2011/schemata/iso19139_2007/schema/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode" codeListValue="publication" codeSpace="ISOTC211/19115">publication</gmd:CI_DateTypeCode>
                  </gmd:dateType>
                </gmd:CI_Date>
              </gmd:date>
            </gmd:CI_Citation>
          </gmd:thesaurusName>
        {% elif value['vocabulary'] %}
          <gmd:thesaurusName>
            <gmd:CI_Citation>
              {% if value['vocabulary']['name'] and value['vocabulary']['url'] %}
              <gmd:title>
                <gmx:Anchor xlink:title="{{ get_charstring(value['vocabulary'].get('name'), record['metadata']['language'], record['metadata']['language_alternate'])[0] }}" xlink:href="{{ value['vocabulary']['url'] }}">{{  get_charstring(value['vocabulary'].get('name'), record['metadata']['language'], record['metadata']['language_alternate'])[0] }}</gmx:Anchor>
              </gmd:title>
              {% elif not value['vocabulary']['url'] %}
              {{ cs.get_freetext('title', record['metadata']['language_alternate'], get_charstring(value['vocabulary'].get('name'), record['metadata']['language'], record['metadata']['language_alternate'])) }}
              {% endif %}
              <gmd:date>
                <gmd:CI_Date>
                  <gmd:date gco:nilReason="missing"/>
                  <gmd:dateType gco:nilReason="missing"/>
                </gmd:CI_Date>
              </gmd:date>
            </gmd:CI_Citation>
          </gmd:thesaurusName>
        {% endif %}
        </gmd:MD_Keywords>
      </gmd:descriptiveKeywords>
      {% endfor %}
      <gmd:resourceConstraints>
        <gmd:MD_LegalConstraints>
          <gmd:accessConstraints>
            <gmd:MD_RestrictionCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_RestrictionCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['identification']['accessconstraints'] }}">{{ record['identification']['accessconstraints'] }}</gmd:MD_RestrictionCode>
          </gmd:accessConstraints>
        </gmd:MD_LegalConstraints>
      </gmd:resourceConstraints>
      <gmd:spatialRepresentationType>
        <gmd:MD_SpatialRepresentationTypeCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_SpatialRepresentationTypeCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['spatial']['datatype'] }}">{{ record['spatial']['datatype'] }}</gmd:MD_SpatialRepresentationTypeCode>
      </gmd:spatialRepresentationType>
      {% if record['identification']['language'] in ['inapplicable', 'missing', 'template', 'unknown', 'withheld'] %}
      <gmd:language gco:nilReason="{{ record['identification']['language'] }}"/>
      {% else %}
      <gmd:language>
        <gmd:LanguageCode codeList="http://www.loc.gov/standards/iso639-2/" codeSpace="ISO 639-2" codeListValue="{{ record['identification']['language'] }}">{{ record['identification']['language'] }}</gmd:LanguageCode>
      </gmd:language>
      {% endif %}
      <gmd:characterSet>
        <gmd:MD_CharacterSetCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_CharacterSetCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['identification']['charset'] }}">{{ record['identification']['charset'] }}</gmd:MD_CharacterSetCode>
      </gmd:characterSet>
      {% for tc in record['identification']['topiccategory'] %}
      <gmd:topicCategory>
        <gmd:MD_TopicCategoryCode>{{ tc }}</gmd:MD_TopicCategoryCode>
      </gmd:topicCategory>
      {% endfor %}
      <gmd:extent>
        <gmd:EX_Extent>
          {% for spatial in record['identification']['extents']['spatial'] %}
          {% set bbox = spatial['bbox'] %}
          <gmd:geographicElement>
            {% if spatial['crs'] != 4326 %}
            <gmd:EX_BoundingPolygon>
              <gmd:extentTypeCode>
                <gco:Boolean>1</gco:Boolean>
              </gmd:extentTypeCode>
              <gmd:polygon>
                <gml:Polygon gml:id="P001" srsName="{{ spatial['crs'] }}" srsDimension="2">
                  <gml:exterior>
                    <gml:LinearRing>
                      <gml:posList srsName="{{ spatial['crs'] }}" srsDimension="2">{{ bbox[0] }} {{ bbox[1] }} {{ bbox[0] }} {{ bbox[3] }} {{ bbox[2] }} {{ bbox[3] }} {{ bbox[2] }} {{ bbox[1] }} {{ bbox[0] }} {{ bbox[1] }}</gml:posList>
                    </gml:LinearRing>
                  </gml:exterior>
                </gml:Polygon>
              </gmd:polygon>
            </gmd:EX_BoundingPolygon>
            {% else %}
            <gmd:EX_GeographicBoundingBox>
              <gmd:extentTypeCode>
                <gco:Boolean>1</gco:Boolean>
              </gmd:extentTypeCode>
              <gmd:westBoundLongitude>
                <gco:Decimal>{{ bbox[0] }}</gco:Decimal>
              </gmd:westBoundLongitude>
              <gmd:eastBoundLongitude>
                <gco:Decimal>{{ bbox[2] }}</gco:Decimal>
              </gmd:eastBoundLongitude>
              <gmd:southBoundLatitude>
                <gco:Decimal>{{ bbox[1] }}</gco:Decimal>
              </gmd:southBoundLatitude>
              <gmd:northBoundLatitude>
                <gco:Decimal>{{ bbox[3] }}</gco:Decimal>
              </gmd:northBoundLatitude>
            </gmd:EX_GeographicBoundingBox>
            {% endif %}
          </gmd:geographicElement>
          {% endfor %}
          {% for temporal in record['identification']['extents']['temporal'] %}
          <gmd:temporalElement>
            <gmd:EX_TemporalExtent>
              <gmd:extent>
                <gml:TimePeriod gml:id="T001">
                  <gml:beginPosition>{{ temporal['begin'] }}</gml:beginPosition>
                  {% if temporal['end'] == 'now' %}
                  <gml:endPosition indeterminatePosition="now"/>
                  {% else %}
                  <gml:endPosition>{{ temporal['end'] }}</gml:endPosition>
                  {% endif %}
                  {% if temporal['resolution'] %}
                  <gml:duration>{{ temporal['resolution'] }}</gml:duration>
                  {% endif %}
                </gml:TimePeriod>
              </gmd:extent>
            </gmd:EX_TemporalExtent>
          </gmd:temporalElement>
          {% endfor %}
        </gmd:EX_Extent>
      </gmd:extent>
      {{ cs.get_freetext('supplementalInformation', record['metadata']['language_alternate'], get_charstring(record['identification'].get('url'), record['metadata']['language'], record['metadata']['language_alternate'])) }}
    </gmd:MD_DataIdentification>
  </gmd:identificationInfo>
  {% if record['content_info'] %}
  <gmd:contentInfo>
    {% if record['content_info']['type'] == 'image' %}
    <gmd:MD_ImageDescription>
      <gmd:attributeDescription>
        <gco:RecordType>{{ record['content_info']['type'] }}</gco:RecordType>
      </gmd:attributeDescription>
      <gmd:contentType>
        <gmd:MD_CoverageContentTypeCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ScopeCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['content_info']['type'] }}">{{ record['content_info']['type'] }}</gmd:MD_CoverageContentTypeCode>
      </gmd:contentType>
      {% for dim in record['content_info']['dimensions'] %}
        <gmd:dimension>
          <gmd:MD_Band id="{{ dim['name'] }}">
            {% if dim['max'] %}
            <gmd:maxValue>
              <gco:Real>{{ dim['max'] }}</gco:Real>
            </gmd:maxValue>
            {% endif %}
            {% if dim['min'] %}
            <gmd:minValue>
              <gco:Real>{{ dim['min'] }}</gco:Real>
            </gmd:minValue>
            {% endif %}
            <gmd:units>
              <gml:UnitDefinition gml:id="units-{{ loop.index }}">
                <gml:identifier codeSpace="none">{{ dim['units'] }}</gml:identifier>
              </gml:UnitDefinition>
            </gmd:units>
          </gmd:MD_Band>
        </gmd:dimension>
      {% endfor %}
      <gmd:cloudCoverPercentage>
        <gco:Real>{{ record['content_info']['cloud_cover'] }}</gco:Real>
      </gmd:cloudCoverPercentage>
      <gmd:processingLevelCode>
        <gmd:RS_Identifier>
          <gmd:code>
            <gco:CharacterString>{{ record['content_info']['processing_level'] }}</gco:CharacterString>
          </gmd:code>
        </gmd:RS_Identifier>
      </gmd:processingLevelCode>
    </gmd:MD_ImageDescription>
    {% endif %}
  </gmd:contentInfo>
  {% endif %}
  <gmd:distributionInfo>
    <gmd:MD_Distribution>
      {% for k, v in record['distribution'].items() %}
      {% if v['format'] and v['format_version'] %}
      <gmd:distributionFormat>
        <gmd:MD_Format>
          <gmd:name>{{ v['format'] }}</gmd:name>
          <gmd:version>{{ v['format_version'] }}</gmd:version>
        </gmd:MD_Format>
      </gmd:distributionFormat>
      {% endif %}
      {% endfor %}
      {% if 'distributor' in record['contact'] %}
      <gmd:distributor>
        <gmd:MD_Distributor>
          <gmd:distributorContact>
          {% set contact = record['contact']['distributor'] %}
          {% set role = 'distributor' %}
          {% include "contact.j2" %}
          </gmd:distributorContact>
        </gmd:MD_Distributor>
      </gmd:distributor>
      {% endif %}
      <gmd:transferOptions>
        <gmd:MD_DigitalTransferOptions>
        {% for v in record['distribution'].values() %}
          <gmd:onLine>
            <gmd:CI_OnlineResource>
              <gmd:linkage>
                <gmd:URL>{{ v['url']|e }}</gmd:URL>
              </gmd:linkage>
              <gmd:protocol>
                <gco:CharacterString>{{ v['type'] }}</gco:CharacterString>
              </gmd:protocol>
              {{ cs.get_freetext('name', record['metadata']['language_alternate'], get_charstring(v.get('name'), record['metadata']['language'], record['metadata']['language_alternate'])) }}
              {{ cs.get_freetext('description', record['metadata']['language_alternate'], get_charstring(v.get('description'), record['metadata']['language'], record['metadata']['language_alternate'])) }}
              {% if v['function'] %}
              <gmd:function>
                <gmd:CI_OnLineFunctionCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_OnLineFunctionCode" codeSpace="ISOTC211/19115" codeListValue="{{ v['function'] }}">{{ v['function'] }}</gmd:CI_OnLineFunctionCode>
              </gmd:function>
              {% elif v['rel'] %}
              <gmd:function>
                <gmd:CI_OnLineFunctionCode codeList="https://www.iana.org/assignments/link-relations/link-relations.xml" codeSpace="rfc8288" codeListValue="{{ v['rel'] }}">{{ v['rel'] }}</gmd:CI_OnLineFunctionCode>
              </gmd:function>
              {% endif %}
            </gmd:CI_OnlineResource>
          </gmd:onLine>
        {% endfor %}
        </gmd:MD_DigitalTransferOptions>
      </gmd:transferOptions>
    </gmd:MD_Distribution>
  </gmd:distributionInfo>
  {% if record['dataquality'] %}
  <gmd:dataQualityInfo>
    <gmd:DQ_DataQuality>
      <gmd:scope>
        <gmd:DQ_Scope>
          <gmd:level>
            <gmd:MD_ScopeCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ScopeCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['dataquality']['scope']['level'] }}">{{ record['dataquality']['scope']['level'] }}</gmd:MD_ScopeCode>
          </gmd:level>
        </gmd:DQ_Scope>
      </gmd:scope>
      <gmd:lineage>
        <gmd:LI_Lineage>
          {{ cs.get_freetext('statement', record['metadata']['language_alternate'], get_charstring(record['dataquality']['lineage'].get('statement'), record['metadata']['language'], record['metadata']['language_alternate'])) }}
        </gmd:LI_Lineage>
      </gmd:lineage>
    </gmd:DQ_DataQuality>
  </gmd:dataQualityInfo>
  {% endif %}
  <gmd:metadataMaintenance>
    <gmd:MD_MaintenanceInformation>
      <gmd:maintenanceAndUpdateFrequency>
        <gmd:MD_MaintenanceFrequencyCode codeList="http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_MaintenanceFrequencyCode" codeSpace="ISOTC211/19115" codeListValue="{{ record['identification']['maintenancefrequency'] }}">{{ record['identification']['maintenancefrequency'] }}</gmd:MD_MaintenanceFrequencyCode>
      </gmd:maintenanceAndUpdateFrequency>
      <gmd:maintenanceNote>
        <gco:CharacterString>This metadata record was generated by pygeometa-{{ pygeometa_version }} (https://github.com/geopython/pygeometa)</gco:CharacterString>
      </gmd:maintenanceNote>
    </gmd:MD_MaintenanceInformation>
  </gmd:metadataMaintenance>
</gmd:MD_Metadata>
